/* 
 * File:   types.h
 * Author: skyro
 *
 * Created on December 16, 2010, 9:56 PM
 */

#ifndef _TYPES_H
#define	_TYPES_H

// 8-bit type
typedef unsigned char           U8;
typedef signed char             I8;

// 16-bit type
typedef unsigned short          U16;
typedef signed short            I16;

// 32-bit type
typedef unsigned int            U32;
typedef signed int              I32;

// 64-bit type
typedef unsigned long long      U64;
typedef signed long long        I64;

// 32-bit float type
typedef float F32;

// 64-bit double type
typedef double F64;

// real number type
#ifdef DOUBLE_PRECISION
// double precision enabled
typedef double Real;
#else
// double precision disabled
typedef float Real;
#endif

// functions for integer endian conversion

#define swap16Bit(x)     (((0x00FF & (U16)(x))<<8) \
                        | ((0xFF00 & (U16)(x))>>8))

#define swap32Bit(x)    (((0x000000FF & (U32)(x))<<24) \
                        |((0x0000FF00 & (U32)(x))<<8) \
                        |((0x00FF0000 & (U32)(x))>>8) \
                        |((0xFF000000 & (U32)(x))>>24))

// functions for float endian conversion
union U32F32
{
    U32 m_asU32;
    F32 m_asF32;
};

inline F32 swapF32(F32 value)
{
    U32F32 u;
    u.m_asF32 = value;
    u.m_asU32 = swap32Bit(u.m_asU32);
    return u.m_asF32;
}

// Error types
typedef enum{kSuccess, kFileOpenFailure} Error;

// alignment computation
template <typename T>
struct alignment
{
    enum{s = sizeof(T), value = s^(s & (s-1))};
};

#define ALIGNOF(T) alignment<T>::value

// intrusive linked list
// the element can reside in multiple link
// at same time
template <typename T>
class Link
{
    Link<T> *mpPrev;
    Link<T> *mpNext;
    T* mpElem;
};

// extrusive linked list
// every element must inherent from this struct
/*template <typename T>
struct ExtrusiveLink
{
    ExtrusiveLink<T>* mpPrev;
    ExtrusiveLink<T>* mpNext;
};*/

/*template <typename T>
class LinkedList
{
public:
    Link<T>* mRoot;
    remove(Link<T>& link);
    

};*/


#define VER_MAJOR 0
#define VER_MINOR 1

#define _DEBUG

#define ASSERTIONS_ENABLED 1

#endif	/* _TYPES_H */

